import Vue from "vue";
import VueRouter from "vue-router";
import Redwine from "../views/redwine.vue"
import Home from "../views/home/Home.vue";
import Category from "../views/category/Category.vue";
import Cart from "../views/cart/Cart.vue";
import ConfirmOrder from '../views/cart/ConfirmOrder.vue'

import Login from "../views/login/Login.vue";
import Register from "../views/login/Register.vue";
import User from "../views/user/User.vue";
import UserInfo from "../views/user/UserInfo.vue";
import UserStore from "../views/user/UserStore.vue";
import UserSetting from "../views/user/UserSetting.vue";

import Order from "../views/order/Order.vue"
import Commit from "../views/order/Commit.vue"

import Address from "../views/address/Address.vue"
import AddAddress from "../views/address/AddAddress.vue"
import EditAddress from "../views/address/EditAddress.vue"
import Classify from "../views/home/Classify.vue";

import Goods from "../views/goods/Goods.vue"
import Search from "../views/search/Search.vue"
import GoodsDetail from "../views/goods/GoodsDetail.vue"
Vue.use(VueRouter);

const routes = [{
    path: '/',
    redirect: '/redwine/home'
  },
  // 没有底部导航的页面
  {
    path: "/login",
    name: "Login",
    component: Login,
  },
  {
    path: "/register",
    name: "Register",
    component: Register,
  },
  {
    path: "/order/:status",
    name: "Order",
    component: Order,
  },
  {
    path: "/commit",
    name: "Commit",
    component: Commit,
  },
  {
    path: "/address",
    name: "Address",
    component: Address,
  },
  {
    path: "/addAddress",
    name: "AddAddress",
    component: AddAddress,
  },
  {
    path: "/editAddress",
    name: "EditAddress",
    component: EditAddress,
  },
  {
    path: "/userInfo",
    name: "UserInfo",
    component: UserInfo,
  },
  {
    path: "/userStore",
    name: "UserStore",
    component: UserStore,
  },
  {
    path: "/userSetting",
    name: "UserSetting",
    component: UserSetting,
  },
  // 有底部导航的页面
  {
    path: "/redwine",
    name: "Redwine",
    component: Redwine,
    redirect: '/redwine/home',
    children: [{
        path: "home",
        name: "Home",
        component: Home,
        meta: {
          path: '/redwine/home'
        }
      },
      {
        path: "category",
        name: "Category",
        component: Category,
        meta: {
          path: '/redwine/category'
        }
      },
      {
        path: "cart",
        name: "Cart",
        component: Cart,
        meta: {
          path: '/redwine/cart'
        }
      },
      {
        path: "user",
        name: "User",
        component: User,
        meta: {
          path: '/redwine/user'
        },
        beforeEnter: (to, from, next) => {
          let username = localStorage.getItem("username");
          if (username) {
            // this.$router.push('/redwine/user')
            next()
          } else {
            router.push('/login')
          }
        }
      }
    ]
  },
  {
    path: "/home/classify/:item",
    name: "Classify",
    component: Classify,
    
  },
  //购物车订单
  {
    path: "/confirmOrder",
    name: "ConfirmOrder",
    component: ConfirmOrder,
  },
    //商品
  {
    path: "/goods",
    name: "Goods",
    component: Goods,
  },
  {
    path: "/search",
    name: "Search",
    component: Search,
  },
  {
    path: "/goodsDetail/:id",
    name: "GoodsDetail",
    component: GoodsDetail,
  },

]

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;